﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TpBaseObjects.Objects;
using TpData.Layer;
using TpLogger;

namespace TpData.Manager {
    public class TecUserDataManager {

        #region Members
        #endregion

        #region Load

        public static TecUserObj LoadTecUser(string LoginName) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                return dl.LoadUser(LoginName);
            }
        }

        public static TecUserObj LoadTecUser(int UserID) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                return dl.LoadUser(UserID);
            }
        }

        public static List<TecUserObj> LoadTecUser() {
            return LoadTecUser(true);
        }

        public static List<TecUserObj> LoadTecUser(bool all) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                return dl.LoadUser(all);
            }
        }

        #endregion

        #region Save

        public static void SaveTecUser(TecUserObj u) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                dl.SaveTecUser(u);
            }
        }

        public static void SaveUserLogin(int userID, DateTime loginTime, string pcName) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                dl.SaveUserLogin(userID, loginTime, pcName);
            }
        }

        public static void SaveUserLogout(int userID) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                dl.SaveUserLogout(userID);
            }
        }

        #endregion

        #region Functions

        public static bool CheckUserIsLoggedIn(int userID) {
            using (TecUserDataLayer dl = CreateTecUserDataLayer()) {
                return dl.CheckUserIsLoggedIn(userID);
            }
        }

        private static TecUserDataLayer CreateTecUserDataLayer() {
            return (DataManager.CreateDataLayer(typeof(TecUserDataLayer)) as TecUserDataLayer);
        }

        #endregion

    }
}
